<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <!-- 引入Vue 全局注册一个名为Vue的构造函数 -->
    <script src="./js/vue.js"></script>
    <title>Vue绑定样式</title>
</head>

<body>

    <style>

        .basic{
            border: 1px,solid,red;
        }
        .style1{
            background-color: red;
        }
        .style2{
            background-color: black;
        }
    </style>
    
  <div id = "root1">
     <!-- class字符串写法适合样式类名不确定，需要动态指定 -->
    <div class="basic" :class="mood" @click="changestyle2">样式切换</div>
    <!-- class数组写法，要绑定的样式个数不确定，名字也不确定 -->
    <div class="basic" :class="classArr" @click="changestyle">样式切换</div>
    <!-- class对象写法，要绑定的样式个数确定，名字确定，但动态决定用不用 -->
    <div class="basic" :class="classObj" @click="changestyle">样式切换</div>
    <!-- style对象写法 -->
    <div class="basic" :style="styleObj" @click="changestyle">样式切换</div>
  </div>

    <script>
        var vm=new Vue({
        el: '#root1',
        data: {
            change:true,
            classArr:['style1','style2','style3'],
            mood:'normal',
            classObj:{
                style1:false,
                style2:false
            },
            styleObj:{
                color:'red',
                backgroudcolor:"black"
            }
        },
        methods:{
          changeStyle(){

          },
          changestyle2(){
             const arr=['style1','style2','style3'];
            let index=Math.floor(random()*3);
            this.mood=arr[index];
          }
        }
        })
    </script>

</body>
</html>